define(function(require){
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");
	var array = require("$UI/system/lib/base/array");
	var SqliteUtil = require("$UI/demo/sqlite/sqliteUtil");
	var Model = function(){
		this.callParent();
	};
	Model.prototype.contents1ActiveChange = function(event){
		var to = event.to;
		
		var button1 = this.comp("button1");
		var button2 = this.comp("button2");
		var button3 = this.comp("button3");
		var button4 = this.comp("button4");
		if (to === 0) {
			button1.set({
				"icon" : "img:$UI/nase/images/dingdanl.png|"
			});
			button2.set({
				"icon" : "img:$UI/nase/images/zf.png|"
			});
			button3.set({
				"icon" : "img:$UI/nase/images/dianping.png|"

			});
			button4.set({
				"icon" : "img:$UI/nase/images/shou.png|"
			});
		}
		if (to === 1) {
			button2.set({
				"icon" : "img:$UI/nase/images/zfl.png|"
			});
			button1.set({
				"icon" : "img:$UI/nase/images/dingdan.png|"
			});
			button3.set({
				"icon" : "img:$UI/nase/images/dianping.png|"
			});
			button4.set({
				"icon" : "img:$UI/nase/images/shou.png|"
			});
		}
		if (to === 2) {
			button3.set({
				"icon" : "img:$UI/nase/images/dianpingl.png|"
			});
			button2.set({
				"icon" : "img:$UI/nase/images/zf.png|"
			});
			button1.set({
				"icon" : "img:$UI/nase/images/dingdan.png|"
			});
			button4.set({
				"icon" : "img:$UI/nase/images/shou.png|"
			});
		}
		if (to === 3) {
			button4.set({
				"icon" : "img:$UI/nase/images/shoul.png|"
			});			
			button3.set({
				"icon" : "img:$UI/nase/images/dianping.png|"
			});		
			button2.set({
				"icon" : "img:$UI/nase/images/zf.png|"
			});			
			button1.set({
				"icon" : "img:$UI/nase/images/dingdan.png|"
			});			
		}
	};

	Model.prototype.UserDataCustomRefresh = function(event){
		var Phone=localStorage.getItem('LoginState');
		var Name = this.getIDByXID('cName');
		var Balance = this.getIDByXID('cBalance');
		var Integral = this.getIDByXID('cIntegral');
		var Image =this.comp('Image');
		justep.Baas.sendRequest({
			"url" : "/nase/nase_action",
			"action" : "queryNase_user",
			"async" : false,
			"params" : {},
			"success" : function(data) {
				array.each(data.rows, function(obj) {
					var fPhone = obj.fPhone.value;
					
					if(Phone == fPhone){
						var fName = obj.fName.value;
						var fIntegral = obj.fIntegral.value;
						var fBalance = obj.fBalance.value;
						var fImgUrl = require.toUrl(obj.fImgUrl.value);
						if(fName != undefined)
							document.getElementById(Name).innerHTML = '<h4 style="color:#FFFFFF;">'+fName+'</h4>';
						document.getElementById(Balance).innerHTML = '<span class="text ceYfQzu">'+fBalance+'</span>';
						document.getElementById(Integral).innerHTML = '<span class="text ceYfQzu">'+fIntegral+'</span>';
						if(fImgUrl != undefined)
							$(Image.domNode).find("img").attr({
								"src" : fImgUrl
							});
							
							
					}
				});
				
			}
		});
	};
	
	Model.prototype.UserDataValueChanged = function(event){
		location.reload();
	};
	Model.prototype.ImageClick = function(event){
		if(localStorage.getItem('LoginState') == " " || localStorage.getItem('LoginState') == undefined){
			justep.Shell.showPage("Login");
		}
	};
	Model.prototype.informationClick = function(event){
		if(localStorage.getItem('LoginState') == " " || localStorage.getItem('LoginState') == undefined){
			justep.Shell.showPage("Login");
		}else
			justep.Shell.showPage("information");
		
	};
	Model.prototype.shopClick = function(event){
		if(localStorage.getItem('LoginState') == " " || localStorage.getItem('LoginState') == undefined){
			justep.Shell.showPage("Login");
		}else
			justep.Shell.showPage("shop");
		
	};

	Model.prototype.harvestClick = function(event){
		if(localStorage.getItem('LoginState') == " " || localStorage.getItem('LoginState') == undefined){
			justep.Shell.showPage("Login");
		}else
			justep.Shell.showPage("address");
	};

	Model.prototype.Phone = function(row){
		var LoginState = localStorage.getItem('LoginState');
		return row.val('fPhone')== LoginState;
	};
	
	Model.prototype.zfPhone = function(row){
		var LoginState = localStorage.getItem('LoginState');
		return row.val('fPhone')== LoginState && row.val('fShop') == '待支付';
	};
	
	Model.prototype.dpPhone = function(row){
		var LoginState = localStorage.getItem('LoginState');
		return row.val('fPhone')== LoginState && row.val('fComment') == '已购买';
	};
	
	Model.prototype.shoppingClick = function(event){
		var data=this.comp("productData"); 
		var UserId = data.getValue("fID");
		justep.Shell.showPage("detail",{
			ID : UserId
		});
	};
	
	return Model;
});